package com.mjk.common.core.jdbc.bean;

import lombok.Getter;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

@Getter
public class Criterion implements Serializable {
    @Serial
    private static final long serialVersionUID = -2420636000497299741L;
    private final String condition;
    private Object value;
    private Object secondValue;
    private boolean noValue;
    private boolean singleValue;
    private boolean betweenValue;
    private boolean listValue;
    private final String typeHandler;

    public Criterion(String condition) {
        this.condition = condition;
        this.typeHandler = null;
        this.noValue = true;
    }

    public Criterion(String condition, Object value, String typeHandler) {
        this.condition = condition;
        this.value = value;
        this.typeHandler = typeHandler;
        if ((value instanceof List))
            this.listValue = true;
        else
            this.singleValue = true;
    }

    public Criterion(String condition, Object value) {
        this(condition, value, null);
    }

    public Criterion(String condition, Object value, Object secondValue,
                     String typeHandler) {
        this.condition = condition;
        this.value = value;
        this.secondValue = secondValue;
        this.typeHandler = typeHandler;
        this.betweenValue = true;
    }

    public Criterion(String condition, Object value, Object secondValue) {
        this(condition, value, secondValue, null);
    }
}
